

const copy = require('copy');
const fs = require('fs');
const transform = require('./transform.js');
const fs2 = require('fs-extra');

function pack(src, dest) {

    if (!fs.statSync(dest).isDirectory() ) {
        throw src + '必须是一个目录';
    }

    if (!fs.statSync(dest).isDirectory()) {
        throw src + '必须是一个目录';
    }

    return copydir(src, dest).then((dir)=> {
        return transform(dir.dest, dir.dest);
    });
   
}

function copydir(src, dest) {
    return new Promise((resolve, reject)=>{
        fs2.copy(src, dest, function (err, files) {
            if (err) {
                throw '不能拷贝代码到' + dest + '目录';
            }
            resolve({src:src,dest:dest});
        });
    });
}

module.exports = pack;